using System.Collections.Generic;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty")]
    public class NpcShouldFlee : AIConditionBaseNode
    {
        // 血量降到多少以下开始逃跑
        public BBParameter<int> healthAmount = 300;
        // 和敌人的最小距离
        public BBParameter<float> minDistance = 10f;

        protected override string info {
            get { return $"npc healthPoint<={healthAmount.value} \nor distance<={minDistance.value}\n then should flee"; }
        }
        
        protected override bool OnCheck()
        {
            BattleAgent battleAgent = _entity.battleAgent;
            if (battleAgent.revengeTarget == null)
            {
                return false;
            }
            
            // 当前血量大于指定值 or 和敌人的距离大于指定值 时，不逃跑
            if(_entity.data.hp > healthAmount.value || Vector3.Distance(battleAgent.transform.position, battleAgent.revengeTarget.transform.position)>=minDistance.value)
            {
                return false;
            }

            return true;
        }
    }
}